package it.xiuxian.login.presenter

import com.lzy.okgo.OkGo
import it.xiuxian.lib.base.BaseBean
import it.xiuxian.lib.base.BasePresenter
import it.xiuxian.lib.base.ILoadBind
import it.xiuxian.lib.http.CallBackOption
import it.xiuxian.lib.http.HttpConfig
import it.xiuxian.lib.utils.EncodeUtils
import it.xiuxian.login.activity.RegisterActivity
import it.xiuxian.login.bean.CodeBean
import it.xiuxian.login.bean.LoginBean
import it.xiuxian.login.bean.RegisterBean
import okhttp3.MediaType
import okhttp3.RequestBody
import org.json.JSONObject
import java.util.*

class RegisterActivityPresenter:BasePresenter<RegisterActivity>() {

    fun getCode(phone: String){
        var json1 = JSONObject()
        json1.put("loginname",phone)
        OkGo.post<BaseBean<String>>(HttpConfig.BASE_URL + "/appregister/sendRegisterSMS")
            .params("encrypt",EncodeUtils.encodeAES(json1.toString()))
            .execute(object : CallBackOption<BaseBean<String>>() {}
                .loadBind(mView as RegisterActivity)
                .execute(object : ILoadBind<BaseBean<String>> {
                    override fun excute(bean: BaseBean<String>) {
                        (mView as RegisterActivity).setData(bean)
                    }
                }) /*  new CallBackOption<BaseBean<LoginBean>>() {}
                        .loadBind(mView)
                        .execute(httpData -> {
                            if (httpData.getData().getGoogleState() == 0) {
                                mView.loginSuccess(httpData.getData());
                            } else {
                                mView.googleCheck(httpData.getData());
                            }
                        })*/
            )
    }
    fun register(phone: String,code:String,invite_code:String,password:String,yaoqingma:String){
        var json1 = JSONObject()
        json1.put("loginname",phone)
            //.put("code",code)
            .put("vcode",invite_code)
            .put("password",password)
            .put("yaoqingma",yaoqingma)
        OkGo.post<BaseBean<String>>(HttpConfig.BASE_URL + "/appregister/register")
            .params("encrypt",EncodeUtils.encodeAES(json1.toString()))
            .execute(object : CallBackOption<BaseBean<String>>() {}
                .loadBind(mView as RegisterActivity)
                .execute(object : ILoadBind<BaseBean<String>> {
                    override fun excute(bean: BaseBean<String>) {
                        (mView as RegisterActivity).setSuccess(bean)
                    }
                }) /*  new CallBackOption<BaseBean<LoginBean>>() {}
                        .loadBind(mView)
                        .execute(httpData -> {
                            if (httpData.getData().getGoogleState() == 0) {
                                mView.loginSuccess(httpData.getData());
                            } else {
                                mView.googleCheck(httpData.getData());
                            }
                        })*/
            )
    }
}